package com.cc.servlet;

import com.alibaba.fastjson.JSON;
import com.cc.service.AttendanceService;
import com.cc.service.impl.AttendanceServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * @author CC
 * @version 1.0
 * @description: TODO
 * @date 2025/3/31 9:30
 */
@WebServlet(urlPatterns = "/attendance")
public class AttendanceServlet extends HttpServlet {
    AttendanceService attendanceService = new AttendanceServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String method = req.getParameter("method");
        switch (method){
            case "clockIn":
                clockIn(req, resp);
                break;
        }


    }

    //打卡
    private void clockIn(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        //获取用户Id
        String employeeId = req.getParameter("employeeId");
        //调用考勤服务
        attendanceService.clockIn(employeeId);
        Map<String, Object> map = new HashMap<>();
        map.put("code", "200");
        map.put("msg", "打卡成功");
        String mapJson = JSON.toJSONString(map);
        resp.getWriter().write(mapJson);

    }
}
